import 'package:flutter/material.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';
import 'package:huajianshe_app/widget/appbar/CAppBar.dart';

class PayPage extends StatefulWidget {

  final String? url;
  final String? title;
  final String? desc;
  final String? price;

  const PayPage(this.url, this.title, this.desc, this.price, {Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _PayPageState();
  }
}

class _PayPageState extends BaseState<PayPage> {

  PayType payType = PayType.wechat;
  bool isAgree = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CAppBar(title: '支付', bgColor: Colors.white, backImgUrl: 'ic_black_arrow',),
      backgroundColor: Colors.white,
      body: Column(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [
        H(5),
        RoundedCornerWidget(margin: EdgeInsets.symmetric(horizontal: 13), padding: EdgeInsets.symmetric(horizontal: 13, vertical: 13), backgroundColor: C.grayF6,
            radius: 13, height: 110,
            child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
              LoadImage('${widget.url}', width: 125, height: 85,),
              W(14),
              Expanded(child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
                ColoredBox(color: Colors.transparent, child: Text('${widget.title}', style: TS(17, C.gray333, fontWeight: FontWeight.bold, height: 0.9),)),
                H(8),
                Container(width: double.infinity, height: 40, alignment: Alignment.topLeft,
                    child: Text('${widget.desc}', style: TS(12, C.gray666), maxLines: 2, overflow: TextOverflow.ellipsis,)
                ),
                H(3),
                Text('¥${widget.price}', style: TS(14, C.primary, fontWeight: FontWeight.bold),)
              ]))
            ],)
        ),
        H(14),
        D(),
        H(17),
        Padding(padding: EdgeInsets.only(left: 13), child: Text('请选择支付方式', style: TS(15, C.gray1A, fontWeight: FontWeight.bold))),
        H(11),
        InkWell(onTap: () => setState((){ payType = PayType.wechat;}), child: Padding(padding: EdgeInsets.all(13),
            child: Row(children: [
              LoadImage('ic_wechat_pay'),
              W(10),
              Text('微信支付', style: TS(16, C.gray333),),
              Spacer(),
               LoadImage(payType == PayType.wechat ? 'ic_radio_checked_22' : 'ic_radio_unchecked_22')
            ])
        )),
        H(9),
        Padding(padding: EdgeInsets.only(left: 45, right: 12), child: D()),
        H(9),
        InkWell(onTap: () => setState((){ payType = PayType.alipay;}), child: Padding(padding: EdgeInsets.all(13),
            child: Row(children: [
              LoadImage('ic_alipay_pay'),
              W(10),
              Text('支付宝', style: TS(16, C.gray333),),
              Spacer(),
              LoadImage(payType == PayType.alipay ? 'ic_radio_checked_22' : 'ic_radio_unchecked_22')
            ])
        )),
        H(9),
        Padding(padding: EdgeInsets.only(left: 45, right: 12), child: D()),
        H(7),
        InkWell(onTap: () => setState((){ isAgree = !isAgree; }), child: Padding(padding: EdgeInsets.all(13),
            child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
              LoadImage(isAgree ? 'ic_radio_checked_22' : 'ic_radio_unchecked_22', width: 15, height: 15,),
              W(7),
              Expanded(child:
              Text('我同意购买守则，我也同意支付以下所示的总金额(含服务费)。', style: TS(12, C.gray666, height: 1.2),))
            ])
        )),
        Spacer(),
        Padding(padding: EdgeInsets.only(left: 27, right: 27, bottom: 17),
            child: SmartButton(width: 320, height: 50, radius: 25, text: '确认并支付', fontSize: 15, textColor: Colors.white, onPressed: pay,),
        )
      ]),
    );
  }

  pay() {
    //todo 支付
  }
}

enum PayType {
  wechat, alipay
}